package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AppTaskDao;
import com.vf.admin.client.dao.AppTaskRecordDao;
import com.vf.admin.client.dao.AppUserDao;
import com.vf.admin.client.service.AppTaskRecordService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppTask;
import com.vf.admin.miaodong.entity.AppTaskRecord;
import com.vf.admin.miaodong.entity.AppUser;
import com.vf.admin.utils.pay.ApiAplayWeChat.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppTaskRecordServiceImpl.java
 * @Description TODO
 * @createTime 2021年07月26日 12:19:00
 */
@Service
public class AppTaskRecordServiceImpl implements AppTaskRecordService {

    @Autowired
    AppTaskRecordDao appTaskRecordDao;

    @Autowired
    AppTaskDao appTaskDao;

    @Autowired
    AppUserDao appUserDao;

    @Override
    public void saveOrUpdate(AppTaskRecord appTaskRecord) {
        appTaskRecordDao.saveOrUpdate(appTaskRecord);
    }

    @Override
    public void addTaskRecord(Integer userid, String typeNameEn) {
        AppTask task = appTaskDao.infoByTypeNameEn(typeNameEn);
        if(org.springframework.util.StringUtils.isEmpty(task)){
            return;
        }

        AppTaskRecord appTaskRecord = new AppTaskRecord();
        appTaskRecord.setUserid(userid);
        AppUser appUser = appUserDao.get(userid);
        if (appUser != null) {
            appTaskRecord.setNick(appUser.getNick());
            appTaskRecord.setPic(appUser.getPic());
        }
        appTaskRecord.setTaskname(task.getTasknameEn());
        //是否领取任务奖励 2领取奖励 3完成任务
        appTaskRecord.setLingqu(2);
        appTaskRecord.setDiamonds(task.getDiamonds());
        appTaskRecord.setCreatetime(new Date());
        appTaskRecordDao.saveOrUpdate(appTaskRecord);
    }

    @Override
    public List<AppTaskRecord> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        return appTaskRecordDao.findList(paramap, splitPageBean);
    }

    @Override
    public AppTaskRecord getByTaskId(Integer userid, Integer taskid) {
        return appTaskRecordDao.getByTaskId(userid, taskid);
    }

    @Override
    public List<AppTaskRecord> list(Map<String, Object> paramap) {
        return appTaskRecordDao.list(paramap);
    }

    @Override
    public Boolean isCompleteToday(Integer userId, String typeNameEn) {
        return appTaskRecordDao.isCompleteToday(userId, typeNameEn);
    }

    @Override
    public Boolean isCompleteOnce(Integer userId, String typeNameEn) {
        return appTaskRecordDao.isCompleteOnce(userId, typeNameEn);
    }
}